package com.jzo2o.customer.controller.consumer;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.model.domain.AddressBook;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.service.IAddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController("AddressBookController")
@RequestMapping(path = "/consumer/address-book")
@Api(tags = "用户端 - 新增地址簿接口")
public class AddressBookController {
    @Resource
    private IAddressBookService addressBookService;


    @PostMapping
    @ApiOperation("新增地址簿")
    public void addAddressBook(@RequestBody AddressBookUpsertReqDTO addressBookUpsertReqDTO) {
        addressBookService.addAddressBook(addressBookUpsertReqDTO);
    }

    @GetMapping(path = "/page")
    @ApiOperation("分页查询地址簿")
    public PageResult<AddressBook> pageAddressBook(AddressBookPageQueryReqDTO addressBookPageQueryReqDTO) {
       return addressBookService.pageAddressBook(addressBookPageQueryReqDTO);
    }

    @GetMapping(path = "/{id}")
    @ApiOperation("地址薄详情")
    public AddressBook AddressBookDetails(@PathVariable Long id) {
        return addressBookService.getById(id);
    }

    @PutMapping(path = "/{id}")
    @ApiOperation("地址薄修改")
    public void updateAddressBook(@PathVariable Long id, @RequestBody AddressBookUpsertReqDTO addressBookUpsertReqDTO) {
        addressBookService.updateAddressBook(id,addressBookUpsertReqDTO);
    }

    @DeleteMapping(path = "/batch")
    @ApiOperation("批量删除地址簿")
    public void deleteAddressBook(@RequestBody List<String> ids) {
        addressBookService.deleteAddressBook(ids);
    }

    @PutMapping(path = "/default")
    @ApiOperation("设置默认地址")
    public void setDefaultAddress(@RequestParam("id") Long id,@RequestParam("flag") Integer flag) {
        addressBookService.setDefaultAddress(id,flag);
    }

    @PutMapping(path = "/defaultAddress")
    @ApiOperation("获取默认地址")
    public AddressBook defaultAddress() {
        return  addressBookService.defaultAddress();
    }
}
